package com.zhang;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.zhang.entity.User;
import com.zhang.service.UserService;
import com.zhang.utils.DemoDataListener;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.File;

/**
 * @program: xinguan-parent
 * @description: 读Excel Test
 * @author: Mr.Zhang
 * @create: 2022-03-09 09:54
 **/

@SpringBootTest
public class SimpleRead {
    @Autowired
    private UserService userService;

    @Test
    public void ti() {
        String fileName = "E:\\15945\\Documents" + File.separator + "用户列表.xlsx";
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(fileName, User.class, new DemoDataListener(userService))
                .excelType(ExcelTypeEnum.XLSX)
                .sheet()
                .doRead();

    }

}
